<?php
// 订购商品
$action=$_GET['action'];
if ($action=="order"){
	$id=checkstr($_POST['id']);
	$num=checkstr($_POST['num']);
	$db->query("select * from ld_product where id='".$id."'",2);
    $rs1=$db->rs;

	setgoodscart($rs1["id"],$rs1["productname"],$num,$rs1["price"],$rs1["pv"],'s');
	echo "<script>location.href='home.php?lsact=mygoodscart';</script>";exit();
}
$id=checkstr($_GET['id']);
$db->query("select * from ld_product where id='".$id."'",2);
$rs=$db->rs;
?>
<link rel="stylesheet" href="../css/datalist.css" type="text/css">
<?php require("topbut.php") ?>
<div class="panel panel-inverse">
	<div class="panel-heading">
	  <p class="panel-title">商品定购</p>
	</div>
	<style type="text/css">
		.prodesc{font-size: 14px;color: #999;margin-top:5px;font-family:"微软雅黑";width:98%;height: auto;overflow: hidden;padding:3px 0;}
		.note.note-info {border-color: #0280b8;color: #fff;height:35px;overflow: hidden;width: 100%;margin-top: 20px;}
		.note {margin-bottom: 20px;border-bottom: 2px solid #0280b8;}
		.note span{display:block;width:100px;text-align:center;line-height:35px;background: #0095D8;border-radius:5px 5px 0 0;font-weight:900;}
		.contdts img{max-width: 100%;}
		.numbipt{border:1px solid #ccc;border-radius: 4px;padding:6px 12px;width:60px;text-align: center;}
		.numbipt:focus{outline: thin dotted;
    outline: 5px auto -webkit-focus-ring-color;
    outline-offset: -2px;}
	</style>
	<div class="panel-body">
		<div class="row">
			<div class="col-md-3">
			     <img src="<?php echo RemoveXSS($rs["proimg"])?>" border="0" width="100%"/>
			</div>
			<div class="col-md-9">
				<form name="form1" method="post" action="control.php"  onsubmit=" return dinggou()">
				 <input type="hidden" name="act" value="dinggou">
				  <input name="id" type="hidden" id="id" value="<? echo $id?>">
				 <input type="hidden" name="price" value="<?php echo $rs["price"];?>">
				 <input type="hidden" name="sx1" id="sx1" value="" >
				 <input type="hidden" name="sx2" id="sx2" value="" >
				 <input type="hidden" name="sx3" id="sx3" value="" >

					<h1 style="font-size:20px;color: #666;font-weight:900;font-family:'微软雅黑';line-height: 40px;"><?php echo $rs["productname"]?></h1>
					<div class="prodesc" style="margin-top: 30px;"><b>产品编号：</b><?php echo $rs["id"]?></div>
					<div class="prodesc"><b>积分价格：</b><?php echo ($rs["price"]*1.0).'.00';?>&nbsp积分</div>
	                <div class="prodesc"><b>库存数：</b><?php echo ($rs["num"]); ?></div>
	                <?php
	                if($rs['style_1_value']){
	                	$arr1=explode('|',$rs['style_1_value']);
	                ?>
	                	<div class="prodesc" id="style_1"><b><?php echo $rs['style_1']?>：</b>
	                	<?php foreach ($arr1 as $key => $v){?>
	                		<input type="button" onclick="setamount('<?php echo  $v ;?>');this.setAttribute('style','color:black;font-weight:bold;');" value="<?php echo $v;?>" />
	                	<?} ?>
	                	</div>
	                <?}
	                ?>
	                <!-- 属性二-->
	                 <?php
	                if($rs['style_2_value']){
	                	$arr2=explode('|',$rs['style_2_value']);
	                ?>
	                	<div class="prodesc" id="style_2"><b><?php echo $rs['style_2']?>：</b>
	                	<?php foreach ($arr2 as $key => $v){?>
	                		<input type="button" onclick="setamount2('<?php echo  $v ;?>');this.setAttribute('style','color:black;font-weight:bold;');" value="<?php echo $v;?>" />
	                	<?} ?>
	                	</div>
	                <?}
	                ?>
	                <!-- 属性三-->
	                 <?php
	                if($rs['style_3_value']){
	                	$arr3=explode('|',$rs['style_3_value']);
	                ?>
	                	<div class="prodesc" id="style_3"><b><?php echo $rs['style_3']?>：</b>
	                	<?php foreach ($arr3 as $key => $v){?>
	                		<input type="button" onclick="setamount3('<?php echo  $v ;?>');this.setAttribute('style','color:black;font-weight:bold;');" value="<?php echo $v;?>" />
	                	<?} ?>
	                	</div>
	                <?}
	                ?>
	                <div class="prodesc" ><b>支付方式：</b>
	                	<select name='pay' id="pay" class="form-control" style="display: inline-block!important;width: 160px;">
	                		<option value="1">积分</option>
	                	</select>
	                	</div>
	                <div class="prodesc"><b>订购数：</b>
	                	<span class="glyphicon glyphicon-minus" id="jian" style="font-size: 12px;cursor: pointer;color:red;"></span>
		                <input name="num" type="text" id="num" value="1" class="numbipt">
		                <span class="glyphicon glyphicon-plus" id="jia" style="font-size: 12px;cursor: pointer;color:red;"></span>
	                </div>
	                <div class="prodesc"><INPUT class="btn btn-md btn-success" type="submit" id="but" value="定购" name="but" style="background:#0095D8;border-color: #0280b8;"> </div>
	            </form>
<div class="order" style="display: none;">
	<form name="form1" method="post" action="control.php" >
				 <input type="hidden" name="act" value="dinggou">
				 <input name="id" type="hidden" id="id" value="<? echo $id?>">
				 <div><b>产品名称：</b><?php echo $rs["productname"]?></div>
				 <div class="prodesc"><input type="text" name="sx1" id="sx1" value="" readonly="readonly"></div>
				 <div class="prodesc"><input type="text" name="sx2" id="sx2" value="" readonly="readonly"></div>
				 <div class="prodesc"><input type="text" name="sx3" id="sx3" value="" readonly="readonly"></div>
				 <div>购买数量：<input type="text" name="sjnum" id="sjnum" value="" readonly="readonly"></div>
				 <div>单价：<?php echo ($rs["price"]*1.0).'.00'; ?>&nbsp积分</div>
				 <div>总积分：  <input type="text" name="sjtot" id="sjtot" value="" readonly="readonly"></div>
				 <div>备注<input type="text" name="beizhu" value=""></div>
				 <input type="hidden" name="price" value="<?php echo $rs["price"];?>">
				 <div class="prodesc"><INPUT class="btn btn-md btn-success" type="submit"  id="but" value="确定购买" name="but"></div>
    </form>

</div>
			</div>
		</div>
		<div class="row">
			<div class="col-md-12 contdts">
				<div class="note note-info"><span>产品详情</span></div>
				<!-- <img src="theme/images/mainbg.jpg"> -->
				<?php echo htmlspecialchars_decode($rs['memo']);?>
			</div>
		</div>



<script type="text/javascript">
function setamount(val){
	var arr = document.getElementById("style_1").getElementsByTagName("input");
	for(var i=0;i<arr.length;i++){
		arr[i].setAttribute("style","color:white;font-weight:normal;");
	}
	if(val){
		document.getElementById("sx1").value=val;
	}else{
		alert('请选择属性！');
	}
}
function setamount2(val){
	var arr = document.getElementById("style_2").getElementsByTagName("input");
	for(var i=0;i<arr.length;i++){
		arr[i].setAttribute("style","color:white;font-weight:normal;");
	}
	if(val){
		document.getElementById("sx2").value=val;
	}else{
		alert('请选择属性！');
	}
}
function setamount3(val){
	var arr = document.getElementById("style_3").getElementsByTagName("input");
	for(var i=0;i<arr.length;i++){
		arr[i].setAttribute("style","color:white;font-weight:normal;");
	}

	if(val){
		document.getElementById("sx3").value=val;
	}else{
		alert('请选择属性！');
	}
}
</script>
<script type="text/javascript" src="/theme/js/jquery.js"></script>
		<script>
		function dinggou(){

			var num=$("#num").val();
			var price=<?php echo $rs["price"];?>;
			var scprice=<?php echo $rs["scprice"];?>;
			var open=<?php echo $GLOBALARR['open_dinggou'];?>;
			tot=num*price;
			xftot=num*scprice;
			if(isNaN(tot)){
				alert("请输入产品的数量");
				return false;
			}
			var type=$("#pay").val();
			if(type !=1 ){
				alert("请选择支付方式，谢谢合作");
				return false;
			}
			if(type==1){
				var txt="收益";
			}
			
			if(open==1){
				alert("暂未开放购买功能");
				return false;
			}
			return(confirm("你将要花费"+tot+"积分,是否确定购买"));


		}
		$('#jian').click(function(){
            var nums = $('#num').val();
            if(!nums){ nums = 0;}
            nums = parseFloat(nums) - 1;
            if(nums <= 0){ nums = 1}
            $('#num').val(nums);
        });
        $('#jia').click(function(){
            var nums = $('#num').val();
            if(!nums){ nums = 0;}
            nums = parseFloat(nums) + 1;
            $('#num').val(nums);
        });
		</script>
	</div>
</div>
